package xyz.lwm.lazycat.utility.metaobject;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author lwm
 */
class MapObject implements MetaObject {

    private final Map<String, Object> map;

    private final List<String> propertyNames;

    public MapObject(Map<String, Object> map) {
        this.map = map;
        this.propertyNames = new ArrayList<>(map.keySet());
    }

    @NotNull
    @Override
    public List<String> findPropertyNames() {
        return propertyNames;
    }

    @Override
    public Object getValue(@NotNull String propertyName) {
        return map.get(propertyName);
    }

    @Override
    public void setValue(@NotNull String propertyName, Object value) {
        // map object, put时无法判断类型, 与 bean object 有区别
        map.put(propertyName, value);
    }

}
